package net.jescort.web.servlet.controller.message;

import net.jescort.domain.forum.Message;
import net.jescort.domain.user.User;
import net.jescort.persistence.dao.MessageDao;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 11-7-16
 * Time: 下午7:02
 */
@Controller
@SessionAttributes(types = Message.class)
public class MessageBoxShow
{
    private MessageDao messageDao;

    @RequestMapping(value = {"/messages/"}, method = RequestMethod.GET)
    public ModelAndView messageBoxHandler()
    {
        ModelAndView mav = new ModelAndView("messages/list");
        User currentUser = (User)SecurityUtils.getSubject().getPrincipal();
        List<Message> messages = messageDao.findByRecipientId(currentUser.getId());
        mav.addObject("messages", messages);
        return mav;
    }
}
